<template>
    <div class="news">
        <div class="main">
            <div class="newCard" v-for="(p, i) of newsList" @click="toDetail(p.id)" :key="i" >
                <div class="title" :title="p.title">
                    <h2>
                       {{p.title}}
                    </h2>
                </div>
                <div class="content">
                    <p>
                        {{p.content}}
                    </p>
                </div>
                <div class="footer">
                    <a-space>
                        <span>作者：{{p.username}}</span>
                        <span>发布时间：{{format(p.UpdatedAt)}}</span>
                    </a-space>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import './styles.less'
import newsAPI from "../../services/news";
import { requestWrapper } from "../../utils/request";
import format  from "../../utils/format";
export default {
    data() {
        return {
            newsList: [],
            format: format,
        }
    },
    methods: {
        toDetail(id) {
           const detail = this.$router.resolve({
                path: '/news_detail',
                query: {
                    newsId: id
                }
            })
            window.open(detail.href,'_blank')
        },
    },
    mounted() {
         requestWrapper( newsAPI.getNewsList.bind(null, {}), {

          }).then((res) => {
              this.newsList = res.list
          })
    }
}
</script>
